package com.ruoyi.project.hcy.product.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.hcy.product.domain.product.Product;
import com.ruoyi.project.hcy.product.domain.product.ProductVo;
import com.ruoyi.project.hcy.product.service.IProductService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName ProShowManagerController
 * @Author SAI
 * @Date 2020/9/20 16:55
 * @Description ProShowManagerController
 * @Version 1.0
 */
@Controller
@RequestMapping("/hcy/product/proShowManager")
public class ProShowManagerController extends BaseController {

    @Autowired
    private IProductService productService;

    private String prefix = "hcy/product/show";

    @RequiresPermissions("product:proShowManager:view")
    @GetMapping()
    public String operlog(){
        return prefix + "/show";
    }

    @RequiresPermissions("product:proShowManager:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Product product){
        startPage();
        List<ProductVo> list = productService.selectShowList(product);
        return getDataTable(list);
    }

    @RequiresPermissions("product:proShowManager:remove")
    @Log(title = "产品管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        try {
            return toAjax(productService.changeStatus(ids));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }
}
